public class Main {
    public static void main(String[] args) {

        int[] nums={1,-2,-3,4};
        Main main = new Main();
        main.getMaxLen(nums);
    }
    //乘积为正数的最⻓⼦数组
    public int getMaxLen(int[] nums) {
        int n = nums.length;
        int[] f=new int[n+1];
        int[] g=new int[n+1];
        f[0]=g[0]=0;
        int ret=Integer.MIN_VALUE;
        for(int i=1;i<=n;i++){
            if(nums[i-1]==0){
                f[i]=g[i]=0;
            } else if(nums[i-1]>0){
                f[i]=f[i-1]+1;
                g[i]=g[i-1]==0?0:g[i-1]+1;
            }else{
                f[i]=g[i-1]==0?0:g[i-1]+1;
                g[i]=f[i-1]+1;
            }
            ret=Math.max(ret,f[i]);
        }
        return ret;
    }

    //等差数列划分
    public int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];
        dp[0]=dp[1]=0;
        int sum=0;
        for(int i=2;i<n;i++){
            dp[i]=nums[i-1]-nums[i-2]==nums[i]-nums[i-1]?dp[i-1]+1:0;
            sum+=dp[i];
        }
        return sum;
    }
}